#include "mysql.hpp"
#include "../../../odb/user.hxx"
#include "../../source/mysql_user.hpp"
#include "user-odb.hxx"
#include <gflags/gflags.h>


DEFINE_bool(run_mode, false, "程序的运行模式,false-调试； true-发布；");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

void insert(chen_im::UserTable& user)
{
    auto user1 = std::make_shared<chen_im::User>("uid1", "昵称1", "123456");
    user.insert(user1);

    auto user2 = std::make_shared<chen_im::User>("uid2", "111222333444");
    user.insert(user2);
}

void update_by_id(chen_im::UserTable &user_tb) {
    auto user = user_tb.select_by_id("uid1");
    user->description("我是一个风一样的男子！！");
    user_tb.update(user);
}

void update_by_phone(chen_im::UserTable &user_tb) {
    auto user = user_tb.select_by_phone("111222333444");
    user->password("22223333");
    user_tb.update(user);
}

int main(int argc, char* argv[])
{
     google::ParseCommandLineFlags(&argc, &argv, true);
    chen_im::init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);
    auto db = chen_im::ODBFactory::create("root", "123456", "127.0.0.1", "chen_im", "utf8", 0, 1);
    chen_im::UserTable user(db);

    // insert(user);
    //update_by_id(user);

    update_by_phone(user);
    return 0;
}
